import { ENUM_DATA_SCOPE } from "@/enum/system.enum";
import { IQuery, TableConfig } from "@/interface/IAxios";
import { getTableConfig } from "@/store/modules/system/system";

export default (columns: Array<any>) => {
  const comTableConfig = computed(() => {
    return getTableConfig();
  });
  const loading = ref(true);

  /* 已经选择的值 */
  const selectedKeys = ref<string[]>([]);

  const rowSelection = ref({
    showCheckedAll: true,
    type: "checkbox",
    onlyCurrent: false
  } as any);

  const tableConfig = ref({
    pageSize: 10,
    total: 0,
    current: 1
  });
  return {
    comTableConfig,
    tableConfig,
    rowSelection,
    selectedKeys,
    loading
  };
};

export const useQuery = <T>(query?: Partial<IQuery> | T): Ref<IQuery<T>> => {
  const obj: IQuery = {
    pageSize: 20,
    pageNum: 1,
    total: 0,
    isAsc: "desc",
    scope: ENUM_DATA_SCOPE.THIS_SHOP_AND_SHARED
  };
  // @ts-ignore
  return ref({
    ...Object.assign(obj, { ...query })
  });
};
export const useTable = <T>(config?: Partial<TableConfig<T>>): Ref<TableConfig<T>> => {
  const data: TableConfig<T> = {
    data: [],
    loading: false,
    rowKey: "",
    keys: []
  };
  // @ts-ignore
  return ref(Object.assign(data, config));
};
